<template>
	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
		
	  <el-form-item label="姓名" prop="wname">
	    <el-input v-model="ruleForm.wname"></el-input>
	  </el-form-item>
	  <el-form-item label="密码" prop="wpassword">
	    <el-input v-model="ruleForm.wpassword"></el-input>
	  </el-form-item>
	  <el-form-item label="级别" prop="wrank">
	    <el-input v-model="ruleForm.wrank"></el-input>
	  </el-form-item>
	  <el-form-item label="电话" prop="wphone">
	    <el-input v-model="ruleForm.wphone"></el-input>
	  </el-form-item>
	  <el-form-item label="工资" prop="wwage">
	    <el-input v-model="ruleForm.wwage"></el-input>
	  </el-form-item>
	  <el-form-item label="备注" prop="wremarks">
	    <el-input v-model="ruleForm.wremarks"></el-input>
	  </el-form-item>
	 
	  <el-form-item>
	    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
	    <el-button @click="resetForm('ruleForm')">重置</el-button>
	  </el-form-item>
	</el-form>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          wname: '',
          wpassword: '',
		  wrank: '',
		  wphone: '',
		  wwage: '',
		  wremarks: ''
        },
        rules: {
          wname: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
          ],
          wpassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ],
          wrank: [
            { required: true, message: '请输入级别', trigger: 'blur' },
          ],
          wphone: [
            { required: true, message: '请输入电话', trigger: 'blur' },
          ],
          wwage: [
            { required: true, message: '请输入工资', trigger: 'blur' },
          ],
          wremarks: [
            { required: true, message: '请输入备注', trigger: 'blur' },
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
		  const _this=this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.put('http://localhost:8181/worker/updateWorker',this.ruleForm).then(function(resp){
				console.log(resp)
				if(resp.data == 'sucess'){
					alert('修改成功')
					_this.$router.push('/WorkerManage')
				}
			})
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
	created() {
		const _this=this
		axios.get('http://localhost:8181/worker/findById/'+this.$route.query.wnum).then(function(resp){
			console.log(resp)
			_this.ruleForm=resp.data
		})
	}
  }
</script>


